import count from '@dfeidao/atom-nodejs/db/count';
import query from '@dfeidao/atom-nodejs/db/query';


interface Message {
	group_number: string;
	productid: string;
	page_size: number;
	page_no: number;
	client_type: string;
	page_name: string;
}

export default async function atom(msg: Message, action_id: string, session_id: string) {
	const systemid = '12';
	const { exec, prepare } = query(action_id, session_id, systemid);
	const productid = msg.productid;
	const client_type = msg.client_type;
	const formname = msg.page_name;
	const aa = {} as { productid: string, client_type: string, formname: {}, group_number: string };
	aa.group_number = msg.group_number;
	if (productid) {
		aa.productid = productid;
	}
	if (client_type) {
		aa.client_type = client_type;
	}
	if (formname) {
		aa.formname = { $like: `%${formname}%` };
	}


	prepare('pub_form', ['formid', 'formname', 'client_type'], aa, msg.page_size, msg.page_no, [], []);
	const [data] = await exec();
	// return aa;
	const c = count(action_id, session_id, systemid);
	c.prepare('pub_form', aa);
	const [t] = await c.exec();
	return { dataArray: data, count: t };
}
